









use Data/accountsales_complete.dta, clear
 	
duplicates drop
	
 
 drop if Salesdr==0 & Consumerdriven ==0 & Renewal==0
 
 duplicates tag account_id contract_start_month sales_channel, gen(tag) //duplicates including sales channel
 
 ** keep first  date 
 
 
 by account_id contract_start_month (contract_start_date), sort: gen dupid=_n
 
 drop if dupid >1 & tag>=1 
 
 
 drop tag
 
 duplicates tag account_id contract_start_month sales_channel, gen(tag) //duplicates including sales channel

 tab tag
 
 
 
 duplicates tag account_id contract_start_month , gen(tag2) // conflicting sales channels within same month - mostly renewal and inbound, or door to door followed by outbound. 
 
 * keep first contact 
 
 drop if tag2>=1 & dupid>1 //

 drop tag2

 duplicates tag account_id contract_start_month , gen(tag2) //duplicates including sales channel

 
 drop contract_start contract_end
 
 merge 1:m account_id contract_start_month using Data/event_study_samplewithsolar.dta

 
 keep if _merge ==3
 
 drop _merge 
 
 save Data/event_study_samplewithsolar_sales.dta, replace
 
 
 drop if ever_solar==1
 drop if has_solar ==1
 
 drop if Other ==1
 
 collapse (mean) DoortoDoor Pricecomparisonwebsite Otherconnectionservice Othersales TelesalesIn TelesalesOut Telesalesunknown Renewal Salesdriven Consumerdriven, by(postcode contract_quarter)
 
 
 save Data/sales_postcodequarter.dta, replace
 
 
